home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
FromTheMag
/
JW FLV MEDIA PLAYER 4.2
/
mediaplayer.exe
/
player.swf
/
scripts
/
com
/
jeroenwijering
/
utils
/
Randomizer.as
< prev
next >
Wrap
Text File
|
2008-11-04
|
1KB
|
64 lines
package com.jeroenwijering.utils
{
public class Randomizer
{
private var todo:Array;
private var done:Array;
private var original:Array;
public function Randomizer(param1:Number)
{
var _loc2_:Number = NaN;
super();
original = new Array();
todo = new Array();
done = new Array();
_loc2_ = 0;
while(_loc2_ < param1)
{
original.push(_loc2_);
_loc2_++;
}
}
public function pick() : Number
{
var _loc1_:Number = NaN;
var _loc2_:Number = NaN;
var _loc3_:Number = NaN;
if(todo.length == 0)
{
_loc3_ = 0;
while(_loc3_ < original.length)
{
todo.push(_loc3_);
_loc3_++;
}
}
_loc1_ = Math.floor(Math.random() * todo.length);
_loc2_ = todo[_loc1_];
done.push(todo.splice(_loc1_,1)[0]);
return _loc2_;
}
public function get length() : Number
{
return todo.length;
}
public function back() : Number
{
if(done.length < 2)
{
return pick();
}
todo.push(done.pop());
return done[done.length - 1];
}
}
}